﻿using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;

namespace Xylee.Common
{
    /// <summary>
    /// Context items are considered to be viewable objects 
    /// using the notify observer pattern, in addition to 
    /// using the state pattern with a priority state.
    /// <remarks><seealso cref="IPersistable"/> is used for 
    /// creating a persistence layer for storing, backing up, 
    /// and restoring context data. This can be done through 
    /// persistence providers. Currently no content is needed 
    /// to implement an IPersistable item, it simply allows 
    /// the providers to either skip over or persist the data
    /// within the object.</remarks>
    /// </summary>
    public abstract class ContextItem : IViewable, IPersistable, INotifyPropertyChanged
    {
        private PropertyManager properties = new PropertyManager();
        protected Context State = Context.None;
        protected Priority Priority = Priority.Normal;

        public ContextItem()
        {
            this.properties.PropertyChanged += new PropertyChangedEventHandler(properties_PropertyChanged);
        }

        private void properties_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if (PropertyChanged != null)
                PropertyChanged(sender, e);
        }

        #region IViewableObject Members

        /// <summary>
        /// Use the indexer of this PropertyManager to 
        /// get and set items. Any time an item changes 
        /// or is added to your properties, you will be 
        /// notified through the property manager.
        /// </summary>
        public PropertyManager Properties
        {
            get { return this.properties; }
        }

        #endregion

        /// <summary>
        /// Refers to the state of a viewed item.
        /// Default state is none.
        /// </summary>
        public enum Context
        {
            Deleted,
            Dirty,
            New,
            Saved,
            None
        }

        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;

        #endregion
    }
}
